//总仓库  商家   用户
import {getProduct,getUserInfo} from '@/api/index'
const state = {
  //商家数据 (商家,商品)
  SellerData:{},

  //用户数据(用户,订单,评价)
  userAll:{}
}
const actions = {
  //获取商家  商品数据
  async getSellerData({commit}){
    let result = await getProduct()
    if(result.code == 200){
      commit('GETSELLERDATA',result.product)
    }
  },

  //获取用户  订单  评价
  async getuserAll({commit}){
    let result = await getUserInfo()
    if(result.code == 200){
      commit('GETUSERALL',result.user)
    }
  }

}
const mutations = {
  GETSELLERDATA(state,val){
    state.SellerData = val
  },

  GETUSERALL(state,val){
    state.userAll = val
  },
}
const getters = {
  //商家数据
  list:state => state.SellerData.seller ? state.SellerData.seller.data.list : [],
  //商品数据
  data:state => state.SellerData.Product.data || [],

  //订单信息
  order:state => state.userAll.order.list  || [],
  //评论信息
  userEvaluate:state => state.userAll.userEvaluate.details || [],
  //用户信息
  userInfo:state => state.userAll.userInfo.details || []
}


export default {
  state,
  actions,
  mutations,
  getters
}